package com.example.demo.customer;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping(path = "api/v1/customer")       //为控制层Controller指定一个路径
@RestController
@Deprecated     //该注解表示该层已经弃用

public class CustomerController {

    private final CustomerService customerService;

    //新建依赖实例
    @Autowired
    private CustomerController(CustomerService customerService){

        this.customerService = customerService;
    }

    @GetMapping(value = "all")      //给GetMapping定义路径为  "api/v1/customer/all"
    List<Customer> getCustomers(){
        return customerService.getCustomers();
    }

    @PostMapping
    void createNewCustomer( @RequestBody Customer customer){
        System.out.println("POST 请求...");
        System.out.println(customer);
    }

    @PutMapping
    void updateCustomer(@RequestBody Customer customer){
        System.out.println("UPDATE 请求");
        System.out.println(customer);
    }


    @DeleteMapping(path = "{customerId}")        // （path = ""）定义了DeleteMapping方法的路径
    void deleteCustomer(@PathVariable("customerId") long id){
        System.out.println("DELETE 请求，删除Customer，其ID为"+ id);
    }

}
